package cn.sccdlg.ssm.dao;

import cn.sccdlg.ssm.domain.Product;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author RaoShuang
 * @emil 991207823@qq.com
 * @date 2020/10/27 21:05
 * 商品持久层
 */
@Repository
@Mapper
public interface IProductDao {

    /**
     * 根据id查询产品
     * @param id 商品id
     */
    @Select("SELECT * FROM product WHERE id=#{id}")
    Product findById(String id) throws Exception;

    /**
     * 查询所有的产品信息
     */
    @Select("SELECT * FROM product")
    List<Product> findAll() throws Exception;

    /**
     * 保存商品
     * @param product 商品信息
     */
    @Insert("INSERT INTO product(id,productNum,productName,cityName,departureTime,productPrice,productDesc,productStatus) " +
            "VALUES(#{id},#{productNum},#{productName},#{cityName},#{departureTime},#{productPrice},#{productDesc},#{productStatus})")
    void save(Product product);

    /**
     * 修改商品信息
     * @param product 商品信息
     */
    @Update("UPDATE product SET productNum=#{productNum},productName=#{productName},cityName=#{cityName},departureTime=#{departureTime}," +
            "productPrice=#{productPrice},productDesc=#{productDesc},productStatus=#{productStatus} WHERE id=#{id}")
    void update(Product product);
}
